<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    //创建核心对象
    var xhttp;
    if (window.XMLHttpRequest){
        xhttp=new XMLHttpRequest();
    }else {
        xhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    //发送请求
    xhttp.open("post","/ajaxdemo/ajaxservlet");
    //设置post请求头
    xhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xhttp.send("a=Ajax&b=hello");
    //获取相应
    xhttp.onreadystatechange=function (){
        if (this.readyState==4 && this.status==200){
            alert(this.responseText);
        }
    };
</script>
</body>
</html>